package cn.yunhe.servlet;

import cn.yunhe.entity.Product;
import cn.yunhe.entity.ProductCategory;
import cn.yunhe.service.ProductCategoryService;
import cn.yunhe.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 这个是修改jsp前所需要的数据
 */
@WebServlet("/UpdateProductPrvServlet")
public class UpdateProductPrvServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pid = Integer.parseInt(request.getParameter("pid"));
        String ppicName = request.getParameter("ppicName");
        String pname = request.getParameter("pname");
        Product product = new Product();
        product.setEpid(pid);
        product.setEppicturename(ppicName);
        product.setEpname(pname);
        ProductService productService = new ProductService();
        Product product1 = productService.getById(pid);
        //查看商品的全部分类
        ProductCategoryService productCategoryService = new ProductCategoryService();
        List<ProductCategory> productCategoryList = productCategoryService.getAllCategory();
        request.setAttribute("productCategoryList",productCategoryList);
        request.setAttribute("product1",product1);
        request.setAttribute("product",product);
        request.getRequestDispatcher("manage/product-modify.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
